package ch.il07.converter.presentation.beans;

import ch.il07.converter.business.MeasurandAction;
import ch.il07.converter.business.ServiceFactoryAdapter;
import ch.il07.converter.presentation.Helper;

public class MeasurandBean {
	private String measurandName;
	private String measurandDescription;
	private String defaultUnit;
	private String unitSymbol;
	private String type;
	private boolean isAdmin = false;

	public MeasurandBean() {
		isAdmin = Helper.isAdministrator();
		type = "private";
	}

	public String process() {
		MeasurandAction ma = ServiceFactoryAdapter.getMeasurandActionInstance();
		if ("private".equals(type) && ma.addPrivateMeasurand(Helper.getUserName(), measurandName, measurandDescription, defaultUnit,  unitSymbol)) {
			return "success";
		} else if ("public".equals(type)
				&& ma.addPublicMeasurand(measurandName, measurandDescription, defaultUnit, unitSymbol)) {
			return "success";
		} else {
			return "failure";
		}
	}

	public String getMeasurandName() {
		return measurandName;
	}

	public void setMeasurandName(String measurandName) {
		this.measurandName = measurandName;
	}

	public String getMeasurandDescription() {
		return measurandDescription;
	}

	public void setMeasurandDescription(String measurandDescription) {
		this.measurandDescription = measurandDescription;
	}

	public String getDefaultUnit() {
		return defaultUnit;
	}

	public void setDefaultUnit(String defaultUnit) {
		this.defaultUnit = defaultUnit;
	}

	public String getUnitSymbol() {
		return unitSymbol;
	}

	public void setUnitSymbol(String unitSymbol) {
		this.unitSymbol = unitSymbol;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public boolean isAdmin() {
		return isAdmin;
	}

	public void setAdmin(boolean isAdmin) {
		this.isAdmin = isAdmin;
	}
}